namespace Sustainalytics.Portfolios.Service.Models
{
    using Sustainalytics.Entities;
    using System.Linq;

    public class PortfolioBaseDtoFactory : PortfolioDtoFactory
    {
        public override PortfolioBase Create(Portfolio portfolio, string createdByUsername)
        {
            return new PortfolioBaseDto
            {
                Id = portfolio.Id,
                Name = portfolio.Name,
                AddedByUserId = portfolio.AddedByUserId,
                IsSystemPortfolio = portfolio.IsAutomatic,
                IsReadonly = portfolio.IsReadonly
            };
        }
    }

    public class SystemPortfolioFactory : SystemPortfolioDtoFactory
    {
        public override SystemPortfolioBaseDto Create(Portfolio portfolio, string createdByUsername)
        {
            return new SystemPortfolioBaseDto() { Id = portfolio.Id, Name = portfolio.Name };
        }
    }

    public class FullDetailsSystemPortfolioFactory : SystemPortfolioDtoFactory
    {
        public override SystemPortfolioBaseDto Create(Portfolio portfolio, string createdByUsername)
        {
            return new SystemPortfolioDto
            {
                Id = portfolio.Id,
                Name = portfolio.Name,
                DataCreated = portfolio.DataCreated,
                DateModified = portfolio.DateModified,
                AddedByFullName = portfolio.AddedByFullName,
                AddedByUserId = portfolio.AddedByUserId,
                AddedByUserName = portfolio.AddedByUserName.ToLowerInvariant(),
                Details = string.Empty,
                CompanyCount = portfolio.CompanyCount,
                SharingStatus = portfolio.SharingStatus,
                IsReadOnly = portfolio.IsReadonly,
                IsMyPortfolio = true,
                HasSubscription = false,
                RelatedUniverses =
                               (portfolio as SystemPortfolio).RelatedUniverses.Select(
                                   x => new RelateduniversesDto() { Id = x.Id, Name = x.Name }).ToArray()
            };
        }
    }
}
